<!doctype html>
<html class="no-js">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport"
          content="width=device-width, initial-scale=1">
    <title>结算页面</title>

    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">

    <!-- No Baidu Siteapp-->
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <link rel="icon" type="image/png" href="i/favicon.png">

    <!-- Add to homescreen for Chrome on Android -->
    <meta name="mobile-web-app-capable" content="yes">
    <link rel="icon" sizes="192x192" href="i/app-icon72x72@2x.png">

    <!-- Add to homescreen for Safari on iOS -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="apple-touch-icon-precomposed" href="i/app-icon72x72@2x.png">

    <!-- Tile icon for Win8 (144x144 + tile color) -->
    <meta name="msapplication-TileImage" content="i/app-icon72x72@2x.png">
    <meta name="msapplication-TileColor" content="#0e90d2">

    <link rel="stylesheet" href="__TMPL__/public/shop/css/amazeui.css">
    <link rel="stylesheet" href="__TMPL__/public/shop/css/jiesuan.css">
    <style>
        .alert-success { color: #3c763d; background-color: #dff0d8; border-color: #d6e9c6;}
    </style>
</head>
<body onload="javascript:return require();">
<div class="alert"></div>
<section class="wapper">
    <div class="am-g am-padding am-posre">
        <!--左边内容-->
        <div class="orderid" ></div>
        <section class="am-u-sm-6 am-u-md-6 am-u-lg-6" >
            <div class="">
                <form class="am-form am-form-horizontal">
                    <div class="am-form-group">
                        <label class="am-u-sm-2 am-form-label">选择加油站：</label>
                        <div class="am-u-sm-10">
                          <select name="shop" id="shop">
                            <foreach name="shop" item="shop">
                                <if condition="$shop.re_guid eq $shop_id">
                                <option selected value="{$shop.re_guid}">{$shop.shop_name}</option>
                                <else/>
                                <option  value="{$shop.re_guid}">{$shop.shop_name}</option>
                                </if>
                            </foreach>
                          </select>
                        </div>
                    </div>
                    <div class="am-form-group input-bg">
                        <label class="am-u-sm-2 am-form-label">金额：</label>
                        <div class="am-u-sm-10">
                            <input type="text" class="am-text-white" id="money" value="">
                        </div>
                    </div>

                    <div class="am-form-group am-bg-white am-border am-margin-top-xl">
                        <label class="am-u-sm-2 am-form-label">优惠券：</label>
                        <div class="am-u-sm-10">
                           <select name="coupon" id="coupon">
                               <option value="0" style="color: red">选择优惠券</option>
                           <foreach name="coupon" item="coupon">
                               <if condition="$coupon['past'] eq 1">
                               <option value="{$coupon.cou_guid}" style="color: red">满{$coupon.voucher_cause}减{$coupon.voucher_money}</option>
                                <else/>
                                <option value="{$coupon.cou_guid}" >满{$coupon.voucher_cause}减{$coupon.voucher_money}</option>
                               </if>
                           </foreach>
                           </select>
                        </div>
                    </div>
                </form>
            </div>
        </section>
        <!--分割线-->
        <div class="am-divider"></div>
        <section class="am-u-sm-6 am-u-md-6 am-u-lg-6">
            <div class="" >
                <div data-am-widget="titlebar" class="am-titlebar am-titlebar-default" >
                    <h2 class="am-titlebar-title">选择其他支付方式</h2>
                </div>
                <div class="am-margin-top am-margin-left-sm pay_type">
                    <ul class="am-list am-avg-sm-3 am-avg-md-3 am-avg-lg-3 am-thumbnails">
                        <li id="weixin">
                            <img class="am-thumbnail" src="__TMPL__/public/shop/img/wx.png" />
                            <label>微信支付</label>
                        </li>
                    </ul>
                </div>
            </div>
        </section>
        <!--右边内容-->

    </div>

</section>

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="__TMPL__/public/shop/js/jquery.js"></script>
<script src="__STATIC__/js/layer/layer.js"></script>
<!--<![endif]-->
<!--[if lte IE 8 ]>
<script src="__TMPL__/public/shop/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->
<script src="__TMPL__/public/shop/js/amazeui.min.js"></script>
<script language="javascript" src="__TMPL__/public/assets/dayin/LodopFuncs.js"></script>
<script>
    /*
    * 余额支付
    * */
    $('#balance').click(function(){
        var order=$('.orderid').html();
        var s_pay=$('#s_pay').val();
        var state=1;
        var index = parent.layer.getFrameIndex(window.name); //获取当前窗体索引
        $.post("{:url('orderpay/pay')}",{state:state,order:order,s_pay:s_pay},function(data){
            var src = '';
            var con=data.msg.con;
            var orderid = data.msg.orderid;
            if(data.msg.sate == 1){
                parent.$('.orderid').html('<input type="hidden" id="orderid" value="">')
                parent.$('#cart').html(src);
                parent.$('.all').html(src);
                $.post("{:url('/home/print/printto')}",{order:orderid},function(date){
                    PrintByPrinterIndex(date.msg);
                    layer.alert('支付成功，请打印成功后关闭', {
                        skin: 'layui-layer-molv', //样式类名
                        closeBtn: 0
                    }, function(){
                        parent.layer.close(index); //执行关闭
                    });
                },'json');
                parent.$('#vip').html(src);
                //setTimeout(function () {
                //parent.layer.close(index); //执行关闭
                //}, 1000);
            }else{
                alert(con);
            }
        },'json')
    })
    /*
   * 现金支付
   * */
    $('#currency').click(function(){
        var order=$('.orderid').html();
        var s_pay=$('#s_pay').val();
        var cash=$('#cash').val();
        if(cash == "")
        {
            alert('请确认是否收钱');
            return false;
        }

        var giveChange=$('#giveChange').val();
        if(giveChange == "")
        {
            alert('请确认是否收钱');
            return false;
        }
        var state=2;
        var index = parent.layer.getFrameIndex(window.name); //获取当前窗体索引
        $.post("{:url('orderpay/pay')}",{state:state,order:order,s_pay:s_pay,giveChange:giveChange,cash:cash},function(data){
            var con=data.msg.con;
            var sate=data.msg.sate;
            var orderid = data.msg.orderid;
            var src = '';
            if(sate == 1)
            {
                parent.$('.orderid').html('<input type="hidden" id="orderid" value="">')
                parent.$('#cart').html(src);
                parent.$('.all').html(src);
                $.post("{:url('/home/print/printto')}",{order:orderid},function(date){
                    PrintByPrinterIndex(date.msg);
                    layer.alert('支付成功，请打印成功后关闭', {
                        skin: 'layui-layer-molv', //样式类名
                        closeBtn: 0
                    }, function(){
                        parent.layer.close(index); //执行关闭
                    });
                },'json');
                parent.$('#vip').html(src);
                //setTimeout(function () {
                //parent.layer.close(index); //执行关闭
                //}, 1000);
            }else{
                alert(con);
            }
        },'json')
    })
    /*
    * 积分支付
    * */
    $('#amend').click(function(){
        var order=$('.orderid').html();
        var s_pay=0;
        var state=3;
        var index = parent.layer.getFrameIndex(window.name); //获取当前窗体索引
        $.post("{:url('orderpay/pay')}",{state:state,order:order,s_pay:s_pay},function(data){
            var src = '';
            var con=data.msg.con;
            var orderid = data.msg.orderid;
            if(data.msg.sate == 1){
                parent.$('.orderid').html('<input type="hidden" id="orderid" value="">')
                parent.$('#cart').html(src);
                parent.$('.all').html(src);
                $.post("{:url('/home/print/printto')}",{order:orderid},function(date){
                    PrintByPrinterIndex(date.msg);
                    layer.alert('支付成功，请打印成功后关闭', {
                        skin: 'layui-layer-molv', //样式类名
                        closeBtn: 0
                    }, function(){
                        parent.layer.close(index); //执行关闭
                    });
                },'json');
                parent.$('#vip').html(src);
                //setTimeout(function () {
                //parent.layer.close(index); //执行关闭
                //}, 1000);
            }else{
                alert(con);
            }
        },'json')
    })
    /*
    * 微信支付
    * */
    $('#weixin').click(function(){
        var money=$('#money').val();
        var state='weixin';
        var re_guid=$('#shop option:selected').val();
        var cou_guid=$('#coupon option:selected').val();
        var index = parent.layer.getFrameIndex(window.name); //获取当前窗体索引
        $.post("{:url('index/order')}",{type:state,money:money,re_guid:re_guid,cou_guid:cou_guid},function(data){
            var src = '';
            var con=data.msg.con;
            var orderid = data.msg.orderid;
            if(data.msg.sate == 1){
                parent.$('.orderid').html('<input type="hidden" id="orderid" value="">')
                parent.$('#cart').html(src);
                parent.$('.all').html(src);
                $.post("{:url('/home/print/printto')}",{order:orderid},function(date){
                    PrintByPrinterIndex(date.msg);
                    layer.alert('支付成功，请打印成功后关闭', {
                        skin: 'layui-layer-molv', //样式类名
                        closeBtn: 0
                    }, function(){
                        parent.layer.close(index); //执行关闭
                    });
                },'json');
                parent.$('#vip').html(src);
            }else{
                alert(con);
            }
        },'json')
    })
    /*
    * 支付宝支付
    * */
    $('#alipay').click(function(){
        var order=$('.orderid').html();
        var s_pay=$('#s_pay').val();
        var state=5;
        var index = parent.layer.getFrameIndex(window.name); //获取当前窗体索引
        $.post("{:url('orderpay/pay')}",{state:state,order:order,s_pay:s_pay},function(data){
            var src = '';
            var con=data.msg.con;
            var orderid = data.msg.orderid;
            if(data.msg.sate == 1){
                parent.$('.orderid').html('<input type="hidden" id="orderid" value="">')
                parent.$('#cart').html(src);
                parent.$('.all').html(src);
                $.post("{:url('/home/print/printto')}",{order:orderid},function(date){
                    PrintByPrinterIndex(date.msg);
                    layer.alert('支付成功，请打印成功后关闭', {
                        skin: 'layui-layer-molv', //样式类名
                        closeBtn: 0
                    }, function(){
                        parent.layer.close(index); //执行关闭
                    });
                },'json');
                parent.$('#vip').html(src);
                //setTimeout(function () {
                // parent.layer.close(index); //执行关闭
                //}, 1000);
            }else{
                alert(con);
            }
        },'json')
    })

    //打印
    var LODOP; //声明为全局变量
    var shuju;
    var shuone;
    var arr = [];
    var arr1 = [];
    var arr2 = [];
    var arr3 = [];

    var pdate = [];
    $.ajax({
        async:false,
        type:"POST",
        url:"/home/Print/printname",
        success:function(dayin){
            pdate = JSON.parse(dayin.msg);
        }
    });
    function PrintByPrinterIndex(date) {
        var shuju = JSON.parse(date);
        CreatePrintPage(shuju);
        if (LODOP.SET_PRINTER_INDEX(pdate.print_name))
            LODOP.PRINT();

        for(var i=1;i<shuju.length;i++){
            //console.log(shuju);return;
            for(var j=0;j<shuju[i].shuliang;j++){
                var ping = [];
                var shul = [];
                ping.push(shuju[i].pinming);
                shul.push(shuju[i].shuliang);
                LODOP=getLodop();
                LODOP.ADD_PRINT_TEXT(20,18,345,31,"流水号:"+shuju[0].num);
                LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
                LODOP.ADD_PRINT_TEXT(40,18,345,31,"订单号:"+shuju[0].dingdan);
                LODOP.SET_PRINT_STYLEA(0,"FontSize",7);
                LODOP.ADD_PRINT_TEXT(53,18,150,31,"品名:"+ping);
                LODOP.SET_PRINT_STYLEA(0,"FontSize",7);
                LODOP.ADD_PRINT_TEXT(66,38,150,31,shuju[i].nature);
                LODOP.SET_PRINT_STYLEA(0,"FontSize",7);
                LODOP.ADD_PRINT_TEXT(80,18,150,31,"数量:1");
                LODOP.SET_PRINT_STYLEA(0,"FontSize",7);
                //LODOP.ADD_PRINT_TEXT(72,18,220,31,"时间:"+shuju[0].付款时间);
                //LODOP.SET_PRINT_STYLEA(0,"FontSize",7);
                //LODOP.SET_PRINTER_INDEXA(0);//指定打印机
                LODOP.SET_LICENSES("","4154EF517CB1509D9291CA6610B5CF0B","C94CEE276DB2187AE6B65D56B3FC2848","");
                LODOP.SET_PRINT_PAGESIZE(1, 400,280, 45,"");
                if (LODOP.SET_PRINTER_INDEX(pdate.print_namebq))
                    LODOP.PRINT();
            }
        }
    };
    function PreviewByPrinterIndex(intPrinterIndex) {
        CreatePrintPage();
        if (LODOP.SET_PRINTER_INDEX(intPrinterIndex))
            LODOP.PREVIEW();
    };
    function CreatePrintPage(shuju) {
        var chang=shuju.length-1;
        LODOP=getLodop();
        LODOP.ADD_PRINT_TEXT(40,65,90,40,"结账单");
        LODOP.SET_PRINT_STYLEA(0,"FontSize",16);
        LODOP.ADD_PRINT_TEXT(60,20,200,40,"流水号:"+shuju[0].num);
        LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
        LODOP.ADD_PRINT_TEXT(80,20,345,31,"订单号:"+shuju[0].dingdan);
        LODOP.SET_PRINT_STYLEA(0,"FontSize",8);
        LODOP.ADD_PRINT_TEXT(95,20,345,31,"收银员:"+shuju[0].收银员);
        LODOP.SET_PRINT_STYLEA(0,"FontSize",8);
        LODOP.ADD_PRINT_TEXT(110,20,345,31,"时间:"+shuju[0].付款时间);
        LODOP.SET_PRINT_STYLEA(0,"FontSize",8);
        LODOP.ADD_PRINT_LINE(125,15,125,170,0,1);
        LODOP.SET_PRINT_STYLEA(1,"FontSize",13);
        LODOP.SET_PRINT_STYLEA(1,"Bold",1);
        LODOP.ADD_PRINT_TEXT(130,20,345,31,"品名");
        LODOP.ADD_PRINT_TEXT(130,80,345,31,"数量");
        LODOP.ADD_PRINT_TEXT(130,110,345,31,"价格");
        LODOP.ADD_PRINT_TEXT(130,145,345,31,"金额");
        LODOP.ADD_PRINT_LINE(142,15,142,170,0,1);
        Pinming(shuju);
        LODOP.ADD_PRINT_LINE(162+(18*chang),15,162+(18*chang),170,0,1);
        LODOP.ADD_PRINT_TEXT(166+(18*chang),20,345,31,"支付方式");
        LODOP.ADD_PRINT_TEXT(166+(18*chang),145,345,31,"金额");
        LODOP.SET_PRINT_STYLEA(0,"FontSize",9);
        LODOP.ADD_PRINT_LINE(180+(18*chang),15,180+(18*chang),170,0,1);
        LODOP.ADD_PRINT_TEXT(184+(18*chang),20,345,31,"现金");
        LODOP.ADD_PRINT_TEXT(184+(18*chang),138,345,31,shuju[0].现金);
        LODOP.ADD_PRINT_LINE(198+(18*chang),15,198+(18*chang),170,1,0);
        LODOP.ADD_PRINT_TEXT(210+(18*chang),20,345,31,"合计:"+shuju[0].合计);
        LODOP.ADD_PRINT_TEXT(210+(18*chang),130,345,31,"优惠:"+shuju[0].优惠);
        LODOP.ADD_PRINT_TEXT(225+(18*chang),20,345,31,"应收:"+shuju[0].应收);
        LODOP.ADD_PRINT_TEXT(240+(18*chang),20,345,31,"实收:"+shuju[0].实收);
        LODOP.ADD_PRINT_TEXT(255+(18*chang),20,345,31,"找零:"+shuju[0].找零);
        LODOP.ADD_PRINT_TEXT(280+(18*chang),55,345,31,"谢谢光临");
        LODOP.SET_PRINT_STYLEA(0,"FontSize",16);
        LODOP.SET_LICENSES("","4154EF517CB1509D9291CA6610B5CF0B","C94CEE276DB2187AE6B65D56B3FC2848","");
        LODOP.SET_PRINT_PAGESIZE(3,500,45,"");//这里3表示纵向打印且纸高“按内容的高度”；500表示纸宽500mm；45表示页底空白4.5mm
    };
    function Pinming(shuju){
        var iCurLine=152;
        for(i=1;i<shuju.length;i++){
            LODOP.ADD_PRINT_TEXT(iCurLine,15,120,60,shuju[i].pinming);
            LODOP.SET_PRINT_STYLEA(0,"FontSize",7);
            LODOP.ADD_PRINT_TEXT(iCurLine+10,15,120,60,shuju[i].nature);
            LODOP.SET_PRINT_STYLEA(0,"FontSize",7);
            LODOP.ADD_PRINT_TEXT(iCurLine,125,25,60,shuju[i].shuliang);
            LODOP.SET_PRINT_STYLEA(0,"FontSize",7);
            LODOP.ADD_PRINT_TEXT(iCurLine,140,32,60,shuju[i].jiage);
            LODOP.SET_PRINT_STYLEA(0,"FontSize",7);
            LODOP.ADD_PRINT_TEXT(iCurLine,160,32,60,shuju[i].金额);
            LODOP.SET_PRINT_STYLEA(0,"FontSize",7);
            iCurLine = iCurLine+18;
        }
    }
</script>
</body>
</html>